<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>view/workArea/parts/myParts</title>
		<!-- css代码 start -->
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../css/global.css" rel="stylesheet" />
		<link href="../../../css/style.css" rel="stylesheet" />
		<link href="../../../css/checkbox.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../css/mui.poppicker.css">
		<link href="../../../css/task.css" rel="stylesheet" />
		<style>
			.d_int_tp{
				border: 0 !important;
				margin-top: 6px !important;
			}
			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
			
			.item_box .item .text{
				padding: 0 17px;
				height: auto;
				line-height: 30px;
				font-size: 14px;
				word-wrap:break-word;
			}
			#statusSel{
				background: #ea1e1a;
				border: 0;
				color: #ddd;
			}
			.select-tzstate{
				width: 100%;
				border: 0;
				color: #a9a9a9;
				font-size: 16px;
				text-align: left;
				padding: 15px;
			}
			.mui-bar-nav{
				box-shadow: 0 1px 6px #ea1e1a;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">我的备件</h1>
		</header>
		<div class="mui-content">
			<div class="details_con select_con" id="search">
				<div class="clum">
					<input type="text" class="d_int_tp" id="partNo" placeholder="请输入备件号" />
				</div>
				<div class="clum">
					<span class="txt" style="width: 100%;">
						<input type="hidden" id="status" value=""/>
						<input type="text" id="statusSel" readonly="readonly" placeholder="请选择备件状态" />
					</span>
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="customerName" placeholder="请输入借货用户名称" />
				</div>
				<div class="clum">
					<input type="hidden" id="istodo" value="0"/>
					<input type="text" class="d_int_tp" id="istodoSel" value="待处理" readonly="readonly" placeholder="请选择是否待处理" />
				</div>
				<div class="btm autoHeight">
					<p class="selectBtn" id="searchBtn" onclick="selectList()">查 询</p>
				</div>
			</div>
			
			<div class="details_con" style="margin: 30px 0 0 0;">
				<div class="item_box" id="itemBox">
				</div>
				<div style="height: 50px;"></div>
			</div>
		</div>
		
		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/mui.picker.js"></script>
		<script src="../../../js/mui.poppicker.js"></script>
		<script src="../../../js/fse/parts/parts.js"></script>

		<script type="text/javascript" charset="utf-8">
			(function($, doc) {
				$.init();
		
				$.plusReady(function() {
					// selectList();
					
					// 备件状态下拉(partsStatus)
					h('#statusSel').tap(function() {
						document.activeElement.blur();
						app.hideSoftKeybord();
						var userPicker = new $.PopPicker();
						app.showWaiting('加载中...')
						ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
							tableName: 'partsStatus',
							engineerId: app.getUser().enginnerId
						}, function(data) {
							app.closeWaiting()
							// console.log(JSON.stringify(data))
							if (!data) {
								app.toast("无下拉内容");
								return false;
							}
							userPicker.setData(data);
							userPicker.show(function(items) {
								h('#statusSel').val(items[0].text)
								h('#status').val(items[0].value)
								userPicker.dispose()
							});
						});
					});
					
					// 是否待处理下拉(partsStatus)
					h('#istodoSel').tap(function() {
						document.activeElement.blur();
						app.hideSoftKeybord();
						var userPicker = new $.PopPicker();
						var data = [{value: '0', text: '待处理'}, {value: '1', text: '已完成'}]
						userPicker.setData(data);
						userPicker.show(function(items) {
							h('#istodoSel').val(items[0].text)
							h('#istodo').val(items[0].value)
							userPicker.dispose()
						});
					});
				});
			}(mui, document));
			
			// 查询工程师备件列表(使用post请求)
			function selectList(){
				var customerName = h("#customerName").val();
				var partNo = h("#partNo").val();
				var status = h("#status").val();
				var istodo = h("#istodo").val();
				var enginnerId = app.getUser().enginnerId;
				
				if (customerName == "" && partNo == "" && status == "" && istodo == "") {
					app.toast("请输入查询条件");
					return false;
				}
				app.showWaiting('加载中...')
				ajaxPost(BASE_URL + "cc/spareParts/queryPartByFseIdPost",{
					"CustName": customerName,
					"Part_no": partNo,
					"Status": status,
					"enginner_id": enginnerId,
					"istodo": istodo
				},function(data) {
					app.closeWaiting()
					// console.log(JSON.stringify(data))
					if (data.code === 200) {
						var str = '';
						var dataObj = JSON.parse(data.data);
						var list = dataObj.record;
						// 无数据
						if (list.length == 0) {
							h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
							return false;
						}
						// 显示列表
						for(var i = 0; i<list.length; i++){
							var info = list[i];
							str += '<div class="item" onclick="jumpToNext(\''+ info.Part_id +'\')">';
							str += '<div class="bar">';
							str += '<span class="number">';
							str += '<img src="../../../images/icon_204.png" />'+ info.Part_no +'</span>';
							str += '</div>';
							str += '<div class="text">';
							str += '<span class="l">备件名称：</span>'+ info.Part_name;
							str += '</div>';
							str += '<div class="type">';
							str += '<p><img src="../../../images/icon_217.png"/>备件数量：<span>'+ info.Part_qty +'</span></p>';
							str += '<p><img src="../../../images/icon_205.png"/>备件状态：<span>'+ partStatusName(info.Status) +'</span></p>';
							str += '<p><img src="../../../images/icon_218.png"/>借货单号：<span>'+ info.Part_DebitNo +'</span></p>';
							str += '<p><img src="../../../images/icon_201.png"/>借货用户名称：<span>'+ emptyStr(info.CustName) +'</span></p>';
							// Consignment Lead Time :计算方式，由发货时间到坏件服务通知关闭/好件备件还库的时间（一旦关联的服务通知关闭/备件好件还库，Consignment Lead Time将无需显示）。
							if (!info.finishtime || info.finishtime == "null" || info.finishtime == "undefined") {
								// console.log(!info.finishtime + "---------" + info.Send_time);
								if (info.Send_time) {
									var dateTime = info.Send_time.replace(/-/g,'/').trim();
									var start = new Date(dateTime);
									var days = timeDifference(start);
									str += '<p><img src="../../../images/icon_202.png"/>Consignment Lead Time：<span>'+ days +'</span></p>';
								} else {
									// 不显示了
									// str += '<p><img src="../../../images/icon_89.png"/>Consignment Lead Time：<span></span></p>';
								}
							}
							str += '</div>';
							str += '</div>';
						}
						// console.log(str)
						h('#itemBox').html(str);
					} else {
						h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
					app.toast("数据获取失败，请检查网络连接");
				});
			}
			
			// 计算时间差
			function timeDifference(start) {
				var end = new Date();
				var cha = end.getTime() - start.getTime();
				var days = (cha/(24*3600*1000)).toFixed(0) //天保留2位小数
				// var days = Math.floor(cha/(24*3600*1000))
				// console.log(cha + "============" + days)
				return days;
			}
			
			// 跳转下一页
			function jumpToNext(Part_id) {
				app.jumpTo("/view/workArea/parts/partsDetail.html","view/workArea/parts/partsDetail", {
					"Part_id" : Part_id
				})
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>